package com.dense.kuiniu.bookborrow.xjSetting.view.other;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.dense.kuiniu.bookborrow.R;
import com.dense.kuiniu.bookborrow.xjSetting.config.ShareKeyConfig;
import com.dense.kuiniu.bookborrow.xjSetting.listener.XJOnClickListener;
import com.dense.kuiniu.bookborrow.xjSetting.manager.PingBaoManager;
import com.dense.kuiniu.bookborrow.xjSetting.utils.SharePreferceUtil;

public class ShiJianLayout extends LinearLayout {
    private String TAG = "ShiJianLayout";

    public ShiJianLayout(Context context) {
        this(context, null);
    }

    public ShiJianLayout(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ShiJianLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }


    private EditText erji_time;
    private EditText sanji_time;
    private TextView save;


    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.shijian_layout, this);

        erji_time = findViewById(R.id.erji_time);
        sanji_time = findViewById(R.id.sanji_time);

        save = findViewById(R.id.jishi_save);
        save.setOnClickListener(onClickListener);

        //二级菜单
       int erv= SharePreferceUtil.getInstance(getContext()).getInt(ShareKeyConfig.ER_JI_CAIDAN,60);
      //三级菜单
       int sanv= SharePreferceUtil.getInstance(getContext()).getInt(ShareKeyConfig.SAN_JI_CAIDAN,60);
        erji_time.setText(String.valueOf(erv));
        sanji_time.setText(String.valueOf(sanv));
    }


    private XJOnClickListener onClickListener = new XJOnClickListener() {
        @Override
        public void onclickView(View view) {
            switch (view.getId()) {
                case R.id.jishi_save:
                    String er = erji_time.getText().toString();
                    String san = sanji_time.getText().toString();
                    if (StringUtils.isEmpty(er) || StringUtils.isEmpty(san)) {
                        ToastUtils.showShort("输入不能为空");
                        return;
                    }
                    try {
                        int opv = Integer.parseInt(er);
                        if (opv >= 1 && opv <= 1000) {
                            SharePreferceUtil.getInstance(getContext()).setCache(ShareKeyConfig.ER_JI_CAIDAN,opv);
                        } else {
                            ToastUtils.showShort("时间，请输入1-1000之间的数字");
                            return;
                        }
                    } catch (Exception e) {
                        ToastUtils.showShort("时间只能是整数！！");
                        return;
                    }
                    try {
                        int cutV = Integer.parseInt(san);
                        if (cutV >= 1 && cutV <= 1000) {
                            SharePreferceUtil.getInstance(getContext()).setCache(ShareKeyConfig.SAN_JI_CAIDAN,cutV);
                        } else {
                            ToastUtils.showShort("时间，请输入1-1000之间的数字");
                            return;
                        }
                    } catch (Exception e) {
                        ToastUtils.showShort("时间只能是整数！！");
                        return;
                    }
                    ToastUtils.showShort("保存成功");
                    break;
            }
        }
    };
}

